
project , uses(../data_output/legislators_klarner.dta)


	**********
	** MAINE House + senate.
	** Consecutive term limites: 4 x 2-year terms.
	** First year: 1996
	**********
		
	use ../data_output/legislators_klarner.dta, clear
	keep if state=="ME" 
	keep if regexm(term, "1985|1987|1989|1991|1993|1995|1997|1999|2001|2003|2005|2007|2009|2011|2013|2015")
	gen lastname = trim(regexs(1)) if regexm(lower(CandName),"([^,]+)")
	gen firstname = trim(regexs(1)) if regexm(lower(CandName),",( [^ ]+)")
	gen mergename = lastname
	bys chamber mergename term: gen n = _n
	by chamber mergename term: egen mean_n=mean(n)
	replace mergename = CandName if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	save ../data_output/legislators_ME_house_1985_2016.dta, replace
	
	gen year_minus0 = year	
	gen year_minus2 = year-2
	gen year_minus4 = year-4
	gen year_minus6 = year-6
	tostring year_minus*, replace
	gen s = year_minus6+";" +year_minus4+";"+year_minus2+";"+ year_minus0 + ";"
	gen termlimited = regexm(elections_won, s)==1 & year>=1994
	save ../data_output/legislators_ME_house_1985_2016.dta, replace
project , creates(../data_output/legislators_ME_house_1985_2016.dta)

	clear
	gen bill = ""
	tempfile tmp
	save `tmp'
	qui foreach i in   127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 {	//   
project , original(../data_input/ME/me_bills`i'.csv)		
		import delimited using ../data_input/ME/me_bills`i'.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8")  varnames(1)  stringcols(_all)
		append using `tmp'
		save `tmp', replace
	}
	
	gen cost_increase = regexm( fiscal_note, "cost increase")
	gen cost_decrease = regexm( fiscal_note, "cost decrease")
	gen revenue_increase = regexm( fiscal_note, "revenue increase")
	gen revenue_decrease = regexm( fiscal_note, "revenue decrease")
	gen tmp = "$0" if regexm( lower(fiscal_note) , "no fiscal impact")
	replace tmp =regexs(1) if  regexm( lower(fiscal_note) , "fund ([($ ][ ,$0-9()]+)")
	replace tmp = subinstr(tmp, ",","",.)
	replace tmp = subinstr(tmp, "$ ","$",.)
	replace tmp = subinstr(tmp, "$","",.)
	replace tmp = subinstr(tmp, "(","-",.)
	replace tmp = subinstr(tmp, ")","",.)
	split tmp, generate(net_cost) parse(" ")
	destring net_cost*, replace
	foreach var of varlist net_cost* {
		replace `var' = -`var'
	}
	egen fiscal_effect = rowmean(net_cost*) 
	replace fiscal_effect = 0 if fiscal_effect==.
	gen sponsor = lower(name)
	gen chamber = ""
	replace chamber = "senate" if regexm(lower(sponsor), "senat|president")
	replace chamber = "house" if regexm(lower(sponsor), "represent|speaker")		
	drop if sponsor==""
	replace sponsor = subinstr(sponsor, ".", "",.)
	gen mergename = regexs(1) if regexm(lower(sponsor), "([^!]+) of ")
	foreach s in representatives representative senators senator president speaker {
		replace mergename = trim( subinstr(mergename, "`s'", "", .) ) 
	}
	*keep if chamber=="house"
	****drop this when we have cosponsor data
	keep if type == "sponsor"
	******************
	gen term = ""
	replace term = "1985-1986" if regexm(session, "112")
	replace term = "1987-1988" if regexm(session, "113")
	replace term = "1989-1990" if regexm(session, "114")
	replace term = "1991-1992" if regexm(session, "115")
	replace term = "1993-1994" if regexm(session, "116")
	replace term = "1995-1996" if regexm(session, "117")	
	replace term = "1997-1998" if regexm(session, "118")
	replace term = "1999-2000" if regexm(session, "119")
	replace term = "2001-2002" if regexm(session, "120")
	replace term = "2003-2004" if regexm(session, "121")
	replace term = "2005-2006" if regexm(session, "122")
	replace term = "2007-2008" if regexm(session, "123")
	replace term = "2009-2010" if regexm(session, "124")
	replace term = "2011-2012" if regexm(session, "125")
	replace term = "2013-2014" if regexm(session, "126")
	replace term = "2015-2016" if regexm(session, "127")
	replace mergename = usubinstr(mergename, "-","",.)
	replace mergename = usubinstr(mergename, "'","",.)
	
	foreach c in É {
		replace mergename = subinstr(mergename, "`c'","e",.)
	}

	replace mergename = "STROUT, BARBARA E." if sponsor=="representative strout of windham"	& regexm(term, "1987|1989")
	replace mergename = "STROUT, DONALD A." if sponsor=="representative strout of corinth"	& regexm(term, "1987|1989")
	replace mergename = "NADEAU, GUY R." if sponsor=="representative nadeau of saco"	& regexm(term, "1985|1987|1989")
	replace mergename = "NADEAU, CATHERINE M." if sponsor=="representative nadeau of winslow"	& regexm(term, "2013")
	replace mergename = "NADEAU, GREGORY G." if sponsor=="representative nadeau of lewiston"	& regexm(term, "1985|1987|1989")
	replace mergename = "NADEAU, ALLEN MICHAEL" if sponsor=="representative nadeau of fort kent"	& regexm(term, "2013")
	replace mergename = "STEVENS, PATRICIA" if sponsor=="representative stevens of bangor"	& regexm(term, "1985|1987|1989|1991")
	replace mergename = "STEVENS, KATHLEEN" if sponsor=="representative stevens of orono"	& regexm(term, "1993")
	replace mergename = "STEVENS, ALBERT G." if sponsor=="representative stevens of sabattus"	& regexm(term, "1985|1987|1989|1991|1993")
	replace mergename = "PARADIS, PATRICK E." if sponsor=="representative paradis of augusta"	& regexm(term, "1985|1987|1989|1991")
	replace mergename = "PARADIS, JUDY" if sponsor=="representative paradis of frenchville"	& regexm(term, "1987|1989|1991")
	replace mergename = "PARADIS, EUGENE J." if sponsor=="representative paradis of old town"	& regexm(term, "1985|1987|1989")
	replace mergename = "BERRY, DONALD P. SR." if sponsor=="representative berry of belmont"	& regexm(term, "1997|1999|2001")
	replace mergename = "BERRY, RANDALL L." if sponsor=="representative berry of livermore"	& regexm(term, "1997|1999|2001")
	replace mergename = "MURPHY, THOMAS W. JR." if sponsor=="representative murphy of kennebunk"	& regexm(term, "1999|2001")
	replace mergename = "MURPHY, ELEANOR M." if sponsor=="representative murphy of berwick"	& regexm(term, "1987|1995|1999|2001")
	replace mergename = "MURPHY, THOMAS" if sponsor=="representative murphy of kennebunk"	& regexm(term, "1987")
	replace mergename = "murphybeck" if sponsor=="representative beck of waterville"	& regexm(term, "2009|2011|2013|2015")
	replace mergename = "CLARK, HERBERT E." if sponsor=="representative clark of millinocket"	& regexm(term, "1987|1989|1991|2009|2011")
	replace mergename = "CLARK, MARGARET P." if sponsor=="representative clark of brunswick"	& regexm(term, "1987|1989|1991")
	replace mergename = "CLARK, TYLER A." if sponsor=="representative clark of easton"	& regexm(term, "2011")
	replace mergename = "RICHARDSON, JOHN G." if sponsor=="representative richardson of brunswick"	& regexm(term, "1999|2003")
	replace mergename = "RICHARDSON, JOHN G." if sponsor=="speaker richardson of brunswick"	& regexm(term, "2005")
	replace chamber = "house" if sponsor=="speaker richardson of brunswick" & regexm(term, "2005")
	replace mergename = "RICHARDSON, WESLEY E." if sponsor=="representative richardson of warren"	& regexm(term, "2005|2007|2009|2011")
	replace mergename = "RICHARDSON, DAVID E." if sponsor=="representative richardson of carmel"	& regexm(term, "2007|2009|2011")
	replace mergename = "RICHARDSON, MAITLAND E." if sponsor=="representative richardson of skowhegan"	& regexm(term, "2003|2005")
	replace mergename = "RICHARDSON, EARL E." if sponsor=="representative richardson of greenville"	& regexm(term, "2005")
	replace mergename = "DUNPHY, LARRY C." if sponsor=="representative dunphy of embden"	& regexm(term, "2015")
	replace mergename = "DUNPHY, MICHELLE ANN" if sponsor=="representative dunphy of old town"	& regexm(term, "2015")
	replace chamber = "house" if regexm(sponsor,"speaker")	& regexm(term, "1991|1989")
	replace mergename = "MARTIN, JOHN L." if regexm(sponsor,"martin of eagle lake")	& regexm(term, "1987|1989|1991|1993|2009|2015")
	replace mergename = "MARTIN, HILDA C." if regexm(sponsor,"representative martin of van buren")	& regexm(term, "1987|1989|1993")
	replace mergename = "MARTIN, JAMES R." if regexm(sponsor,"representative martin of orono")	& regexm(term, "2009")
	replace mergename = "MARTIN, ROLAND DANIEL" if regexm(sponsor,"representative martin of sinclair")	& regexm(term, "2015")
	replace mergename = "REED, GARY W." if regexm(sponsor,"representative reed of falmouth")	& regexm(term, "1991|1993|1995")
	replace mergename = "REED, WILLIAM F." if regexm(sponsor,"representative reed of dexter")	& regexm(term, "1991|1995")
	replace mergename = "CARROLL, DONNELL P." if regexm(sponsor,"representative carroll of gray")	& regexm(term, "1989|1991")
	replace mergename = "CARROLL, JOHN H." if regexm(sponsor,"representative carroll of southwest harbor")	& regexm(term, "1989|1991")
	replace mergename = "MITCHELL, JAMES" if regexm(sponsor,"representative mitchell of freeport")	& regexm(term, "1991|1993")
	replace mergename = "MITCHELL, ELIZABETH H." if regexm(sponsor,"mitchell of vassalboro")	& regexm(term, "1991|1993|1995|1997")
	replace mergename = "MITCHELL, J. ELIZABETH" if regexm(sponsor,"representative mitchell of portland")	& regexm(term, "1995|1997")
	replace mergename = "BAILEY, RONALD C." if regexm(sponsor,"representative bailey of farmington")	& regexm(term, "1991|1993")
	replace mergename = "BAILEY, HARRY" if regexm(sponsor,"representative bailey of township 27")	& regexm(term, "1991|1993")
	replace mergename = "LIBBY, JACK L." if regexm(sponsor,"representative libby of kennebunk")	& regexm(term, "1993|1995")	
	replace mergename = "LIBBY, JAMES D." if regexm(sponsor,"representative libby of buxton")	& regexm(term, "1993|1995")
	replace mergename = "LIBBY, AARON F." if regexm(sponsor,"representative libby of waterboro")	& regexm(term, "2013")
	replace mergename = "LIBBY, NATHAN L." if regexm(sponsor,"representative libby of lewiston")	& regexm(term, "2013")
	replace mergename = "TOWNSEND, GEORGE A." if regexm(sponsor,"representative townsend of eastport")	& regexm(term, "1993")
	replace mergename = "TOWNSEND, ELIZABETH" if regexm(sponsor,"representative townsend of portland")	& regexm(term, "1993")
	replace mergename = "JONES, SUMNER A. JR." if regexm(sponsor,"representative jones of pittsfield")	& regexm(term, "1995|1997")
	replace mergename = "JONES, KYLE W." if regexm(sponsor,"representative jones of bar harbor")	& regexm(term, "1995|1997")
	replace mergename = "JONES, SHARON LIBBY" if regexm(sponsor,"representative jones of greenville")	& regexm(term, "1997")
	replace mergename = "WHEELER, EDGAR" if regexm(sponsor,"representative wheeler of bridgewater")	& regexm(term, "1997|1999|2001")
	replace mergename = "WHEELER, GARY J." if regexm(sponsor,"representative wheeler of eliot")	& regexm(term, "1997|1999|2001")
	replace mergename = "PINKHAM, WILLIAM D." if regexm(sponsor,"representative pinkham of lamoine")	& regexm(term, "1997")
	replace mergename = "PINKHAM, REGINALD G." if regexm(sponsor,"representative pinkham of brunswick")	& regexm(term, "1997")
	replace mergename = "BELANGER, IRVIN G." if regexm(sponsor,"representative belanger of caribou")	& regexm(term, "1997")
	replace mergename = "BELANGER, DUANE J." if regexm(sponsor,"representative belanger of wallagrass")	& regexm(term, "1997")
	replace mergename = "BAKER, CHRISTINA L." if regexm(sponsor,"representative baker of bangor")	& regexm(term, "1997")	
	replace mergename = "BAKER, JOHN" if regexm(sponsor,"representative baker of dixfield")	& regexm(term, "1997")
	replace mergename = "SAXL, JANE W." if regexm(sponsor,"representative saxl of portland")	& regexm(term, "1997|1999")
	replace mergename = "SAXL, MICHAEL V." if regexm(sponsor,"representative saxl of bangor")	& regexm(term, "1997|1999")
	replace mergename = "TOBIN, JAMES H. JR." if regexm(sponsor,"representative tobin of dexter")	& regexm(term, "1999|2001|2003")
	replace mergename = "TOBIN, DAVID L." if regexm(sponsor,"representative tobin of windham")	& regexm(term, "2001")
	replace mergename = "SAVAGE, CHRISTINE R." if regexm(sponsor,"representative savage of union")	& regexm(term, "1999")	
	replace mergename = "SAVAGE, WILLIAM R." if regexm(sponsor,"representative savage of buxton")	& regexm(term, "1999")
	replace mergename = "DAVIS, GERALD M." if regexm(sponsor,"representative davis of falmouth")	& regexm(term, "2005")
	replace mergename = "MUSE, CHRISTOPHER T." if regexm(sponsor,"representative muse of south portland")	& regexm(term, "2001")
	replace mergename = "MUSE, KEVIN M." if regexm(sponsor,"representative muse of fryeburg")	& regexm(term, "2001")
	replace mergename = "OBRIEN, JULIE ANN" if regexm(sponsor,"representative o'brien of augusta")	& regexm(term, "2001|2003")
	replace mergename = "OBRIEN, LILLIAN LAFONTAINE" if regexm(sponsor,"representative o'brien of lewiston")	& regexm(term, "2001|2003")
	replace mergename = "DUPREY, BRIAN M." if regexm(sponsor,"representative duprey of hampden")	& regexm(term, "2003")
	replace mergename = "DUPREY, GUY J. JR." if regexm(sponsor,"representative duprey of medway")	& regexm(term, "2003")
	replace mergename = "MILLS, JANET T." if regexm(sponsor,"representative mills of farmington")	& regexm(term, "2003")
	replace mergename = "MILLS, S. PETER" if regexm(sponsor,"representative mills of cornville")	& regexm(term, "2003")
	replace mergename = "SMITH, NANCY E." if regexm(sponsor,"representative smith of monmouth")	& regexm(term, "2003|2005")
	replace mergename = "SMITH, WILLIAM J." if regexm(sponsor,"representative smith of van buren")	& regexm(term, "2003|2005")
	replace mergename = "HANLEY, BRUCE Q." if regexm(sponsor,"representative hanley of paris")	& regexm(term, "2005")
	replace mergename = "HANLEY, STEPHEN P." if regexm(sponsor,"representative hanley of gardiner")	& regexm(term, "2005")
	replace mergename = "PERRY, JOSEPH C." if regexm(sponsor,"representative perry of bangor")	& regexm(term, "2003")
	replace mergename = "PERRY, ANNE C." if regexm(sponsor,"representative perry of calais")	& regexm(term, "2003")
	replace mergename = "WAGNER, RICHARD V." if regexm(sponsor,"representative wagner of lewiston")	& regexm(term, "2009")
	replace mergename = "WAGNER, JOSEPH A." if regexm(sponsor,"representative wagner of lyman")	& regexm(term, "2009")
	replace mergename = "CROCKETT, JARROD S." if regexm(sponsor,"representative crockett of bethel")	& regexm(term, "2009")
	replace mergename = "CROCKETT, PATSY GARSIDE" if regexm(sponsor,"representative crockett of augusta")	& regexm(term, "2009")
	replace mergename = "JOHNSON, PETER B." if regexm(sponsor,"representative johnson of greenville")	& regexm(term, "2011|2013")	
	replace mergename = "JOHNSON, DAVID D." if regexm(sponsor,"representative johnson of eddington")	& regexm(term, "2011|2013")
	replace mergename = "CAMPBELL, JAMES J. SR." if regexm(sponsor,"representative campbell of newfield")	& regexm(term, "2013|2015")
	replace mergename = "CAMPBELL, RICHARD H." if regexm(sponsor,"representative campbell of orrington")	& regexm(term, "2013|2015")
	replace mergename = "KINNEY, JONATHAN LEE" if regexm(sponsor,"representative kinney of limington")	& regexm(term, "2015")
	replace mergename = "KINNEY, MARYANNE" if regexm(sponsor,"representative kinney of knox")	& regexm(term, "2015")
	replace mergename = "WILLETTE, ALEXANDER REGINALD" if regexm(sponsor,"representative willette of mapleton")	& regexm(term, "2011")
	replace mergename = "WILLETTE, MICHAEL J." if regexm(sponsor,"representative willette of presque isle")	& regexm(term, "2011")
	replace mergename = "BURNS, DAVID C." if regexm(sponsor,"representative burns of whiting")	& regexm(term, "2011")
	replace mergename = "BURNS, DAVID R." if regexm(sponsor,"representative burns of alfred")	& regexm(term, "2011")
	replace mergename = "DILL, JAMES F." if regexm(sponsor,"representative dill of old town")	& regexm(term, "2011")
	replace mergename = "DILL, CYNTHIA A." if regexm(sponsor,"representative dill of cape elizabeth")	& regexm(term, "2011")		
	replace mergename = "MACDONALD, W. BRUCE" if regexm(sponsor,"representative macdonald of boothbay")	& regexm(term, "2013")
	replace mergename = "MACDONALD, SHARRI K." if regexm(sponsor,"representative macdonald of old orchard beach")	& regexm(term, "2013")
	replace mergename = "PIERCE, JEFFREY K." if regexm(sponsor,"representative pierce of dresden")	& regexm(term, "2015")
	replace mergename = "PIERCE, TERESA S." if regexm(sponsor,"representative pierce of falmouth")	& regexm(term, "2015")
	replace mergename = "lisink" if regexm(sponsor,"lisnik")	& regexm(term, "1985|1987|1989")
	replace mergename = "peaveyhaskell" if regexm(sponsor,"peavey haskell")	& regexm(term, "2001")
	replace mergename = "strangburgess" if regexm(sponsor,"strang burgess")	& regexm(term, "2007|2009|2011")
	replace mergename = "laverriereboucher" if regexm(mergename,"laverrierebouc")	& regexm(term, "2001|2003")
	replace mergename = "salisbury" if regexm(mergename,"salsbury")	& regexm(term, "1985|1987")	
	replace mergename = "tippingspitz" if regexm(mergename,"tipping")	& regexm(term, "2013|2015")
	replace mergename = "monaghanderrig" if regexm(mergename,"monaghan")	& regexm(term, "2013|2015")
	replace mergename = "russellnatera" if regexm(mergename,"russell")	& regexm(term, "2009|2011|2013")
	replace mergename = "haskell" if regexm(mergename,"peavey haskell")	& regexm(term, "2013")
	replace mergename = "cornellduhoux" if regexm(mergename,"cornell du houx")	& regexm(term, "2009|2011")
	replace mergename = "vanwie" if regexm(mergename,"van wie")	& regexm(term, "2009")
	replace mergename = "pelletiersimpson" if regexm(mergename,"simpson")	& regexm(term, "2001|2003|2005|2007|2009")	
	replace mergename = "bryantdeschenes" if regexm(mergename,"bryantdeschene")	& regexm(term, "2003|2005")
	replace mergename = "saintonge" if regexm(sponsor,"representative st")	& regexm(term, "1991|1993")
	replace mergename = "quint" if regexm(sponsor,"representative birney of paris")	& regexm(term, "1993")
	replace mergename = "wintle" if regexm(sponsor,"wintle")	& regexm(term, "2011")
	replace mergename = "trahan" if regexm(sponsor,"trahan")	& regexm(term, "2011")
	replace chamber = "house" if regexm(sponsor,"wintle")	& regexm(term, "2011")
	replace chamber = "senate" if regexm(sponsor,"trahan")	& regexm(term, "2011")
	replace mergename = "BAKER, HARLAN" if regexm(sponsor,"representative baker of portland")	& regexm(term, "1985")
	replace mergename = "BAKER, ALAN L." if regexm(sponsor,"representative baker of orrington")	& regexm(term, "1985")
	replace mergename = "BROWN, DARRYL N." if regexm(sponsor,"representative brown of livermore falls")	& regexm(term, "1985")
	replace mergename = "BROWN, ADA K." if regexm(sponsor,"representative brown of gorham")	& regexm(term, "1985")
	replace mergename = "HIGGINS, LINWOOD M." if regexm(sponsor,"representative higgins of scarborough")	& regexm(term, "1985")
	replace mergename = "HIGGINS, H. CRAIG" if regexm(sponsor,"representative higgins of portland")	& regexm(term, "1985")
	replace mergename = "MARTIN, JOHN L." if regexm(sponsor,"representative martin of eagle lake")	& regexm(term, "1985")
	replace mergename = "MARTIN, HILDA C." if regexm(sponsor,"representative martin of van buren")	& regexm(term, "1985")
	replace mergename = "MURPHY, ELEANOR M." if regexm(sponsor,"representative murphy of berwick")	& regexm(term, "1985|1987")
	replace mergename = "MURPHY, THOMAS" if regexm(sponsor,"representative murphy of kennebunk")	& regexm(term, "1985")
	replace mergename = "SMITH, CARL B." if regexm(sponsor,"representative smith of island falls")	& regexm(term, "1985")	  
	replace mergename = "brennan" if mergename == "brennanxx"
	replace mergename = "peaveyhaskell" if mergename == "peavey haskell"
	replace mergename = "MILLS, S. PETER" if regexm(mergename,"mills")	& regexm(term, "2003")
	replace mergename = "PERRY, JOSEPH C." if regexm(mergename,"perry")	& regexm(term, "2003")
	replace mergename = "RICHARDSON, JOHN G." if regexm(sponsor,"richardson of brunswick")	& regexm(term, "1999|2003")
	replace mergename = "BERRY, RANDALL L." if regexm(sponsor,"representative berry of livermore")	& regexm(term, "1997|1999|2001")
	replace mergename = "BERRY, DONALD P. SR." if regexm(sponsor,"representative berry of belmont")	& regexm(term, "1997|1999|2001")
	replace mergename = "MURPHY, ELEANOR M." if regexm(sponsor,"representative murphy of berwick")	& regexm(term, "1995|1999|2001")
	replace mergename = "MURPHY, THOMAS W. JR." if regexm(sponsor,"representative murphy of kennebunk")	& regexm(term, "1999|2001")
	replace mergename = "CLARK, HERBERT E." if regexm(sponsor,"representative clark of millinocket")	& regexm(term, "1987|1989|1991")
	replace mergename = "CLARK, MARGARET P." if regexm(sponsor,"representative clark of brunswick")	& regexm(term, "1987|1989|1991")
	replace mergename = "PARADIS, PATRICK E." if regexm(sponsor,"representative paradis of augusta")	& regexm(term, "1985|1987|1989|1991")
	replace mergename = "PARADIS, JUDY" if regexm(sponsor,"representative paradis of frenchville")	& regexm(term, "1987|1989|1991")
	replace mergename = "NADEAU, GREGORY G." if regexm(sponsor,"representative nadeau of lewiston")	& regexm(term, "1985|1987|1989")
	replace mergename = "NADEAU, GUY R." if regexm(sponsor,"representative nadeau of saco")	& regexm(term, "1985|1987|1989")
	replace mergename = "STROUT, DONALD A." if regexm(sponsor,"representative strout of corinth")	& regexm(term, "1987|1989")
	replace mergename = "STROUT, BARBARA E." if regexm(sponsor,"representative strout of windham")	& regexm(term, "1987|1989")
	replace mergename = "PARADIS, EUGENE J." if regexm(sponsor,"representative paradis of old town")	& regexm(term, "1985|1987|1989")
	replace mergename = "STEVENS, ALBERT G." if regexm(sponsor,"representative stevens of sabattus")	& regexm(term, "1985|1987|1989")
	replace mergename = "STEVENS, PATRICIA" if regexm(sponsor,"representative stevens of bangor")	& regexm(term, "1985|1987|1989")
	replace mergename = "MURPHY, THOMAS" if regexm(sponsor,"representative murphy of kennebunk")	& regexm(term, "1987")
	replace chamber = "house" if [ regexm(mergename, "bliss|craven|gerzofsky|jackson|pelletiersimpson|rector") & regexm(term, "2007") ] 
	replace chamber = "house" if [ regexm(mergename, "bliss|craven|gerzofsky|jackson|pelletiersimpson|rector|trahan") & regexm(term, "2005") ] 
	replace chamber = "house" if [ regexm(mergename, "andrews|bliss|cowger|courtney|craven|gerzofsky|jackson|pelletiersimpson|rosen|snowemello|sullivan|trahan|MILLS, S. PETER|PERRY, JOSEPH C.") & regexm(term, "2003") ] 
	replace chamber = "senate" if [ regexm(mergename, "martin|pendleton|richardson|rotundo|treat") & regexm(term, "2003") ] 
	replace chamber = "senate" if [ regexm(mergename, "martin|rotundo") & regexm(term, "2005") ] 
	replace chamber = "senate" if [ regexm(mergename, "martin|rotundo") & regexm(term, "2007") ] 
		
	merge m:1 chamber mergename term using ../data_output/legislators_ME_house_1985_2016.dta

	
	//141 observations are not merging
	drop if _merge==1
	gen law = 0
	replace law = 1 if regexm(lower(status), "finally passed|enacted|veto overridden| signed")
	drop sponsor
	gen sponsor = 1 if bill!=""
	gen billlength = length(billtext)
	gen sponsor_approp = regexm( lower(cmt_assign), "approp")
	gen fiscal_analysis = fiscal_link!=""
	gen fiscal_positive = fiscal_effect>0
	gen fiscal_negative = fiscal_effect<0
	gen fiscal_neutral = fiscal_effect==0
	gen law_fiscal_effect = 0 if fiscal_effect!=.
	replace law_fiscal_effect = fiscal_effect if law==1
	
	save ../data_output/bills_by_sponsor_ME_1985_2016.dta, replace
project , creates(../data_output/bills_by_sponsor_ME_1985_2016.dta)	

	use ../data_output/bills_by_sponsor_me_1985_2016.dta, clear
	
	collapse (sum) fiscal_analysis fiscal_positive fiscal_negative fiscal_neutral sponsor* law billlength total_fiscal_effect = fiscal_effect (mean) law_fiscal_effect  mean_fiscal_effect = fiscal_effect (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party mergename inoffice year termlimited vtsh, by(CandId term )
	foreach v of varlist sponsor_approp billlength *fiscal* {
		bys term: egen max = max(`v')
		replace `v' = . if max==0
		drop max
	}
	save ../data_output/total_bills_by_sponsor_ME_1985_2016.dta, replace
project, creates(../data_output/total_bills_by_sponsor_ME_1985_2016.dta)
	
	
	**Voting
	
	**voting in ME
	use ../data_output/legislators_ME_house_1985_2016.dta, clear
	keep if regexm(term, "2003|2005|2007|2009|2011|2013|2015")
	gen os_mergename = regexs(1) if regexm(lower(CandName),"(^[^,]+),")
	bys chamber os_mergename term: gen n = _n
	by chamber os_mergename term: egen mean_n=mean(n)
	replace os_mergename = lower(CandName) if mean_n>1
	drop n mean_n
	tempfile tmp
	save `tmp'
	
	
	**data on voting
project, original(../data_input/ME/me_votes.csv)	
	import delimited using ../data_input/ME/me_votes.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varnames(1)
	gen chamber = lower(location)
	gen term = ""
	replace term = "2003-2004" if regexm(session, "121")
	replace term = "2005-2006" if regexm(session, "122")
	replace term = "2007-2008" if regexm(session, "123")
	replace term = "2009-2010" if regexm(session, "124")
	replace term = "2011-2012" if regexm(session, "125")
	replace term = "2013-2014" if regexm(session, "126")
	replace term = "2015-2016" if regexm(session, "127")
	keep if regexm(term, "2003|2005|2007|2009|2011|2013|2015")
	gen os_mergename = regexs(1) if regexm(lower(name), "^([^!]+) of")
	replace os_mergename = lower(os_mergename)
	replace os_mergename = subinstr(os_mergename,"’","",.)
	replace os_mergename = subinstr(os_mergename,"'","",.)
	replace os_mergename = subinstr(os_mergename,"-","",.)
	replace os_mergename = regexr(os_mergename, "É", "e")
	replace os_mergename = "burns, david c." if name=="BURNS of Whiting" & regexm(term, "2011")
	replace os_mergename = "burns, david r." if name=="BURNS of Alfred" & regexm(term, "2011")
	replace os_mergename = "brennan" if os_mergename=="brennanxx" & regexm(term, "2003")
	replace os_mergename = lower("CAMPBELL, JAMES J. SR.") if name=="CAMPBELL of Newfield" & regexm(term, "2013|2015")
	replace os_mergename = lower("CAMPBELL, RICHARD H.") if name=="CAMPBELL of Orrington" & regexm(term, "2013|2015")
	replace os_mergename = lower("CHURCHILL, JOHN W.") if name=="CHURCHILL of Washburn" & regexm(term, "2003")
	replace os_mergename = lower("CHURCHILL, EUGENE L.") if name=="CHURCHILL of Orland" & regexm(term, "2003")
	replace os_mergename = lower("CLARK, TYLER A.") if name=="CLARK of Easton" & regexm(term, "2009|2011")
	replace os_mergename = lower("CLARK, HERBERT E.") if name=="CLARK of Millinocket" & regexm(term, "2009|2011")
	replace os_mergename = lower("CROCKETT, PATSY GARSIDE") if name=="CROCKETT of Augusta" & regexm(term, "2009")
	replace os_mergename = lower("CROCKETT, JARROD S.") if name=="CROCKETT of Bethel" & regexm(term, "2009")
	replace os_mergename = lower("DAVIS, GERALD M.") if name=="DAVIS of Cumberland" & regexm(term, "2005")
	replace os_mergename = lower("DAVIS, KIMBERLY J.") if name=="DAVIS of Augusta" & regexm(term, "2005")
	replace os_mergename = lower("DILL, CYNTHIA A.") if name=="DILL of Cape Elizabeth" & regexm(term, "2011")	
	replace os_mergename = lower("DILL, JAMES F.") if name=="DILL of Old Town" & regexm(term, "2011")
	replace os_mergename = lower("DUNPHY, LARRY C.") if name=="DUNPHY of Embden" & regexm(term, "2015")
	replace os_mergename = lower("DUNPHY, MICHELLE ANN") if name=="DUNPHY of Old Town" & regexm(term, "2015")
	replace os_mergename = lower("DUPREY, BRIAN M.") if name=="DUPREY of Hampden" & regexm(term, "2003")
	replace os_mergename = lower("DUPREY, GUY J. JR.") if name=="DUPREY of Medway" & regexm(term, "2003")
	replace os_mergename = lower("HANLEY, STEPHEN P.") if name=="HANLEY of Gardiner" & regexm(term, "2005")
	replace os_mergename = lower("HANLEY, BRUCE Q.") if name=="HANLEY of Paris" & regexm(term, "2005")
	replace os_mergename = lower("JOHNSON, PETER B.") if name=="JOHNSON of Greenville" & regexm(term, "2011|2013")
	replace os_mergename = lower("johnson, david d.") if name=="JOHNSON of Eddington" & regexm(term, "2011|2013")	
	replace os_mergename = lower("KINNEY, JONATHAN LEE") if name=="KINNEY of Limington" & regexm(term, "2015")	
	replace os_mergename = lower("KINNEY, MARYANNE") if name=="KINNEY of Knox" & regexm(term, "2015")	
	replace os_mergename = lower("LIBBY, AARON F.") if name=="LIBBY of Waterboro" & regexm(term, "2013")	
	replace os_mergename = lower("LIBBY, NATHAN L.") if name=="LIBBY of Lewiston" & regexm(term, "2013")	
	replace os_mergename = lower("MACDONALD, W. BRUCE") if name=="MacDONALD of Boothbay" & regexm(term, "2013")	
	replace os_mergename = lower("MACDONALD, SHARRI K.") if name=="MacDONALD of Old Orchard Beach" & regexm(term, "2013")		
	replace os_mergename = lower("MARTIN, JOHN L.") if name=="MARTIN of Eagle Lake" & regexm(term, "2009|2015")	
	replace os_mergename = lower("MARTIN, ROLAND DANIEL") if regexm(name, "MARTIN of Sinclair") & regexm(term, "2015")	
	replace os_mergename = lower("MARTIN, JAMES R.") if regexm(name, "MARTIN of Orono") & regexm(term, "2009")	
	replace os_mergename = lower("NADEAU, CATHERINE M.") if regexm(name, "NADEAU of Winslow") & regexm(term, "2013")	
	replace os_mergename = lower("NADEAU, ALLEN MICHAEL") if regexm(name, "NADEAU of Fort Kent") & regexm(term, "2013")	
	replace os_mergename = lower("MILLS, S. PETER") if regexm(name, "MILLS of Somerset") & regexm(term, "2003")	
	replace os_mergename = lower("MILLS, JANET T.") if regexm(name, "MILLS of Farmington") & regexm(term, "2003")	
	replace os_mergename = lower("monaghanderrig") if regexm(name, "MONAGHAN of Cape Elizabeth") & regexm(term, "2013|2015")	
	replace os_mergename = lower("murphybeck") if regexm(name, "BECK of Waterville") & regexm(term, "2009|2011|2013|2015")	
	replace os_mergename = lower("peaveyhaskell") if regexm(name, "PEAVEY HASKELL of Milford") & regexm(term, "2003")	
	replace os_mergename = lower("haskell") if regexm(name, "PEAVEY HASKELL of Milford") & regexm(term, "2013")	
	replace os_mergename = lower("PIERCE, JEFFREY K.") if regexm(name, "PIERCE of Dresden") & regexm(term, "2015")	
	replace os_mergename = lower("PIERCE, TERESA S.") if regexm(name, "PIERCE of Falmouth") & regexm(term, "2015")	
	replace os_mergename = lower("OBRIEN, LILLIAN LAFONTAINE") if regexm(name, "O'BRIEN of Lewiston") & regexm(term, "2003")	
	replace os_mergename = lower("OBRIEN, JULIE ANN") if regexm(name, "O'BRIEN of Augusta") & regexm(term, "2003")	
	replace os_mergename = lower("pelletiersimpson") if regexm(name, "SIMPSON of Androscoggin") & regexm(term, "2003|2005|2007|2009")	
	replace os_mergename = lower("PERRY, JOSEPH C.") if regexm(name, "PERRY of Penobscot") & regexm(term, "2003")	
	replace os_mergename = lower("PERRY, ANNE C.") if regexm(name, "PERRY of Calais") & regexm(term, "2003")	
	replace os_mergename = lower("russellnatera") if regexm(name, "RUSSELL of Portland") & regexm(term, "2009|2011|2013")	
	replace os_mergename = lower("RICHARDSON, DAVID E.") if regexm(name, "RICHARDSON of Carmel") & regexm(term, "2005|2007|2009|2011")	
	replace os_mergename = lower("RICHARDSON, EARL E.") if regexm(name, "RICHARDSON of Greenville") & regexm(term, "2003|2005|2007")	
	replace os_mergename = lower("RICHARDSON, JOHN G.") if regexm(name, "RICHARDSON of Brunswick") & regexm(term, "2003|2005")	
	replace os_mergename = lower("RICHARDSON, MAITLAND E.") if regexm(name, "RICHARDSON of Skowhegan") & regexm(term, "2003|2005")	
	replace os_mergename = lower("RICHARDSON, WESLEY E.") if regexm(name, "RICHARDSON of Warren") & regexm(term, "2005|2007|2009|2011")	
	replace os_mergename = lower("SMITH, NANCY E.") if regexm(name, "SMITH of Monmouth") & regexm(term, "2003|2005")	
	replace os_mergename = lower("SMITH, WILLIAM J.") if regexm(name, "SMITH of Van Buren") & regexm(term, "2003|2005")	
	replace os_mergename ="strangburgess" if  os_mergename =="strang burgess"
	replace os_mergename ="vanwie" if  os_mergename =="van wie"	
	replace os_mergename = lower("tippingspitz") if regexm(name, "TIPPING of Orono") & regexm(term, "2013|2015")	
	replace os_mergename = lower("TOBIN, DAVID L.") if regexm(name, "TOBIN of Windham") & regexm(term, "2003")	
	replace os_mergename = lower("tobin, james h. jr.") if regexm(name, "TOBIN of Dexter") & regexm(term, "2003")		
	replace os_mergename = lower("WAGNER, RICHARD V.") if regexm(name, "WAGNER of Lewiston") & regexm(term, "2009")	
	replace os_mergename = lower("WAGNER, JOSEPH A.") if regexm(name, "WAGNER of Lyman") & regexm(term, "2009")	
	replace os_mergename = lower("WILLETTE, ALEXANDER REGINALD") if regexm(name, "WILLETTE of Mapleton") & regexm(term, "2011")	
	replace os_mergename = lower("WILLETTE, MICHAEL J.") if regexm(name, "WILLETTE of Presque Isle") & regexm(term, "2011")	
	replace os_mergename = lower("CORNELLDUHOUX") if regexm(name, "CORNELL du HOUX of Brunswick") & regexm(term, "2009|2011")	
		
	merge m:1 chamber os_mergename term using `tmp'
	drop if _merge==1
	drop _merge

	
	egen vote_id = group(bill chamber date motion)
	replace vote = "1" if lower(vote)=="y"
	replace vote = "-1" if lower(vote)=="n"
	replace vote = "0" if lower(vote)!="1" & lower(vote)!="-1"
	destring vote, replace
	gen floorvotes= vote!=0
	bys party vote_id : egen party_mean=mean(vote)
	gen party_vote = 0
	replace party_vote = 1 if party_mean>0
	replace party_vote = -1 if party_mean<0
	gen vote_party_line = vote==party_vote
	gen vote_against_party = vote==-party_vote
	bys vote_id: egen votemargin = mean(vote)
	gen close_floorvotes = floorvotes if abs(votemargin)<.1			
		
	
	*floor votes
	save ../data_output/floorvotes_ME_2003_2016.dta, replace
project , creates(../data_output/floorvotes_ME_2003_2016.dta)	
	
	use ../data_output/floorvotes_ME_2003_2016.dta, clear
	collapse  (mean) vote_party_line vote_against_party (sum) *floorvotes (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party mergename inoffice year termlimited vtsh, by(CandId term )
	save ../data_output/total_floorvotes_ME_2003_2016.dta, replace	
project , creates(../data_output/total_floorvotes_ME_2003_2016.dta)	
	
